package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.StaffingPo;
import com.ruoyi.erp.service.IStaffingPoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外派项目POController
 * 
 * @author sauger
 * @date 2022-03-22
 */
@Controller
@RequestMapping("/erp/po")
public class StaffingPoController extends BaseController
{
    private String prefix = "erp/po";

    @Autowired
    private IStaffingPoService staffingPoService;

    @RequiresPermissions("erp:po:view")
    @GetMapping()
    public String po()
    {
        return prefix + "/po";
    }

    /**
     * 查询外派项目PO列表
     */
    @RequiresPermissions("erp:po:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StaffingPo staffingPo)
    {
        startPage();
        List<StaffingPo> list = staffingPoService.selectStaffingPoList(staffingPo);
        return getDataTable(list);
    }

    /**
     * 导出外派项目PO列表
     */
    @RequiresPermissions("erp:po:export")
    @Log(title = "外派项目PO", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StaffingPo staffingPo)
    {
        List<StaffingPo> list = staffingPoService.selectStaffingPoList(staffingPo);
        ExcelUtil<StaffingPo> util = new ExcelUtil<StaffingPo>(StaffingPo.class);
        return util.exportExcel(list, "外派项目PO数据");
    }

    /**
     * 新增外派项目PO
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存外派项目PO
     */
    @RequiresPermissions("erp:po:add")
    @Log(title = "外派项目PO", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StaffingPo staffingPo)
    {
        return toAjax(staffingPoService.insertStaffingPo(staffingPo));
    }

    /**
     * 修改外派项目PO
     */
    @RequiresPermissions("erp:po:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        StaffingPo staffingPo = staffingPoService.selectStaffingPoById(id);
        mmap.put("staffingPo", staffingPo);
        return prefix + "/edit";
    }

    /**
     * 修改保存外派项目PO
     */
    @RequiresPermissions("erp:po:edit")
    @Log(title = "外派项目PO", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StaffingPo staffingPo)
    {
        return toAjax(staffingPoService.updateStaffingPo(staffingPo));
    }

    /**
     * 删除外派项目PO
     */
    @RequiresPermissions("erp:po:remove")
    @Log(title = "外派项目PO", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(staffingPoService.deleteStaffingPoByIds(ids));
    }
}
